package mop.exception;

import java.sql.Timestamp;
import java.util.Date;

import mop.model.resource.Resource;

/**
 * Exception class for unvailable resources.
 * 
 * @author	 MOP Team 7
 */
public class UnavailableResourceException extends Throwable 
{

	/**
	 * Initializes an UnavailableResourceException with the given resource and time period
	 * 
	 * @param 	resource	The resource name.
	 * @param	start		Start time of reservation
	 * @param	duration	Duration period of reservation
	 *  
	 * @post 	Sets the resource.
	 * @post	Sets the start date
	 * @post	Sets the duration time
	 */
	public UnavailableResourceException(Resource resource, Date start, Date duration)
	{
		this.resource = resource;
		this.start = start;
		this.duration = duration;
	}
	
	/**
	 * Return a error message that can be used by the gui
	 * 
	 * @return An error message describing the incorrect user
	 */
	public String toString()
	{
		
		StringBuffer sb = new StringBuffer();
		sb.append("The following resource is unavailable! ");
		
		if(this.resource == null)
			sb.append("NULL");
		else
		{
			sb.append(this.resource.getDescription());
		}
		
		sb.append("For given time period: "+start+" "+ new Timestamp(start.getTime()+duration.getTime()));
		
		return sb.toString();
		
	}
	
	/**
	 * weird java demand
	 */
	private static final long serialVersionUID = 1L;
	
	/**
	 * The start time
	 */
	private final Date start;
	
	/**
	 * The duration
	 */
	private final Date duration;
	
	/**
	 * The resource that's causing the problem
	 */
	private final Resource resource;
	
}